package cn.bkrc.controller;

import cn.bkrc.entity.Dept;
import cn.bkrc.reporsity.DeptRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    DeptRepository deptRepository;

    @GetMapping("/dept/{did}")
    //根据id查找dept信息
    public Dept findDeptById(@PathVariable("did") Integer did){
       Dept dept =deptRepository.findById(did).get();
        return dept;
    }

    //查看所有dept信息
    @GetMapping("/dept")
    public List<Dept> findAllDepts(){
        return deptRepository.findAll();
    }

    //添加dept信息
    @PostMapping("/dept")
    public Dept addDept(Dept dept){
        Dept dept1=deptRepository.save(dept);
        return  dept1;
    }

    //修改dept信息
    @PutMapping("/dept")
    public Dept updeEmp(Dept dept){
        Dept dept1=deptRepository.save(dept);
        return  dept1;
    }

    //根据id删除dept信息
    @DeleteMapping("/dept/{did}")
    public void deleteDeptById(@PathVariable("did") Integer did){
        deptRepository.deleteById(did);
    }
}
